<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>企业准入管理</title>
    <link rel="stylesheet" href="../../component/pear/css/pear.css"/>
</head>
<body class="pear-container">
<style>
    .edit-btn {
        border: 0;
        background: 0;
        color: #0000FF;
        font-size: 14px;
    }

    .edit-btn:hover {
        border: 0;
        background: 0;
        font-size: 14px;
    }

    .addunit {
        background-color: #2D8CF0 !important;
        color: white;
        border: 0;
        height: 34px;
        line-height: 34px;
        padding: 0 10px;
        font-size: 12.5px;
        cursor: pointer;
    }

    .layui-form-label {
        width: 120px;
    }
    .layui-form-item .layui-inline{
        margin-right: unset!important;
    }
</style>


<div class="layui-card">
    <div class="layui-card-body">
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">企业名称</label>
                    <div class="layui-input-inline">
                        <input type="text" name="enterprise_name\@like" class="layui-input" autocomplete="off">
                    </div>
                </div>
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">法人姓名</label>
                    <div class="layui-input-inline">
                        <input type="text" name="legal_name\@like" class="layui-input" autocomplete="off">
                    </div>
                </div>
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">统一社会信用代码</label>
                    <div class="layui-input-inline">
                        <input type="text" name="credit_code\@like" class="layui-input" autocomplete="off">
                    </div>
                </div>
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">受理单位</label>
                    <div class="layui-input-inline">
                        <input type="text" name="acceptance_unit\@like" class="layui-input" autocomplete="off">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">是否为负面清单</label>
                    <div class="layui-input-inline">
                        <select name="negative_state" xm-selects="negativeState" xm-select-skin="default">
                            <option value="">请选择</option>
                            <option value="0">是</option>
                            <option value="1">否</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">是否为黑名单</label>
                    <div class="layui-input-inline">
                        <select name="black_list" xm-selects="blackList" xm-select-skin="default">
                            <option value="">请选择</option>
                            <option value="0">是</option>
                            <option value="1">否</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item layui-inline">
                    <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="busUnit-query">
                        <i class="layui-icon layui-icon-search"></i>
                        查询
                    </button>
                    <button type="reset" class="pear-btn pear-btn-md">
                        <i class="layui-icon layui-icon-refresh"></i>
                        重置
                    </button>
                </div>
            </div>
        </form>
    </div>
</div>

<div class="layui-card">
    <div class="layui-card-body">
        <table id="busUnit-table" lay-filter="busUnit-table"></table>
    </div>
</div>

<script type="text/html" id="busUnit-toolbar">
    <button class="pear-btn pear-btn-primary pear-btn-md" lay-event="addunit">
        <i class="layui-icon layui-icon-add-1"></i>
        新增
    </button>
    <button class="pear-btn pear-btn-danger pear-btn-md" lay-event="batchRemove">
        <i class="layui-icon layui-icon-delete"></i>
        删除
    </button>
</script>
<script type="text/html" id="busUnit-bar">
    <button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="edit" title="编辑"><i
            class="layui-icon layui-icon-edit"></i></button>
    <button class="pear-btn pear-btn-danger pear-btn-sm" lay-event="remove" title="删除"><i
            class="layui-icon layui-icon-delete"></i></button>
</script>

<script type="text/html" id="driver_license-bar">
    <button class="pear-btn  pear-btn-sm edit-btn" lay-event="lookup">
        查看
    </button>
</script>

<script type="text/html" id="busUnit-access_status">
    {{#if (d.accessStatus == 0) { }}
    <span>有效</span>
    {{# }else if(d.accessStatus == 1){ }}
    <span>无效</span>
    {{# } }}
</script>

<script type="text/html" id="busUnit-black_list">
    {{#if (d.blackList == 0) { }}
    <span>是</span>
    {{# }else if(d.blackList == 1){ }}
    <span>否</span>
    {{# } }}
</script>

<script type="text/html" id="busUnit-negative_state">
    {{#if (d.negativeState == 0) { }}
    <span>是</span>
    {{# }else if(d.negativeState == 1){ }}
    <span>否</span>
    {{# } }}
</script>
<script type="text/html" id="black-enable">
    <input type="checkbox" name="black_flag" value="{{d.id}}" lay-skin="switch" lay-text="是|否"
           lay-filter="black-enable" {{d.black_flag==0?'checked':''}}>
</script>
<script type="text/html" id="nelist-enable">
    <input type="checkbox" name="nelist_flag" value="{{d.id}}" lay-skin="switch" lay-text="是|否"
           lay-filter="nelist-enable" {{d.nelist_flag==0?'checked':''}}>
</script>
</script>
<script src="../../component/layui/layui.js"></script>
<script src="../../component/pear/pear.js"></script>
<script>
    layui.use(['table', 'form', 'jquery', 'common'], function () {
        let table = layui.table;
        let form = layui.form;
        let $ = layui.jquery;
        let common = layui.common;

        let VIEW_PATH = "${ctxPath}/busUnit/view/";
        let DATA_PATH = "${ctxPath}/busUnit/data/";

        let cols = [[
            {type: 'checkbox'},
            {title: '企业名称', field: 'enterpriseName', align: 'center', width: 220},
            {title: '社会统一信用代码', field: 'creditCode', align: 'center', width: 180},
            {title: '法人姓名', field: 'legalName', align: 'center'},
            {title: '法人电话', field: 'legalPhone', align: 'center'},
            {title: '准入状态', field: 'accessStatus', align: 'center', templet: '#busUnit-access_status'},
            {title: '受理单位', field: 'acceptanceUnit', align: 'center'},
            {title: '黑名单', field: 'black_flag', align: 'center', templet: '#black-enable'},
            {title: '负面清单', field: 'nelist_flag', align: 'center', templet: '#nelist-enable'},
            {title: '安全积分', field: 'safetyPoints', align: 'center'},
            {title: '操作', toolbar: '#busUnit-bar', align: 'center', width: 120}
        ]]

        table.render({
            elem: '#busUnit-table',
            url: DATA_PATH + 'list',
            page: true,
            cols: cols,
            skin: 'line',
            defaultToolbar: "",
            height: 'full-260',
            toolbar: '#busUnit-toolbar',
            // defaultToolbar: [
            //     {
            //     title: '刷新',
            //     layEvent: 'refresh',
            //     icon: 'layui-icon-refresh',
            // }, 'filter', 'print', 'exports'
            // ]
        });

        table.on('tool(busUnit-table)', function (obj) {
            if (obj.event === 'remove') {
                window.remove(obj);
            } else if (obj.event === 'edit') {
                window.saveOrUpdate(obj);
            }
        });

        table.on('toolbar(busUnit-table)', function (obj) {
            if (obj.event === 'addunit') {
                layer.open({
                    type: 2,
                    title: '新增外包单位',
                    shade: 0.1,
                    area: [common.isModile() ? '100%' : '750px', common.isModile() ? '100%' : '400px'],
                    content: VIEW_PATH + 'saveOrUpdate'
                });
            } else if (obj.event === 'refresh') {
                window.refresh();
            } else if (obj.event === 'batchRemove') {
                window.batchRemove(obj);
            }
        });

        form.on('submit(busUnit-query)', function (data) {
            table.reload('busUnit-table', {
                where: data.field,page: {curr: 1}
            })
            return false;
        });

        form.on('switch(black-enable)', function (obj) {
            var flag = obj.elem.checked;
            var text = "确定要拉入黑名单吗？";
            if (!flag) {
                text = "确定要拉出黑名单吗？";
            }
            layer.confirm(text, {
                icon: 3,
                title: '提示'
            }, function (index) {
                layer.close(index);
                let loading = layer.load();
                $.post(DATA_PATH + "control", {
                    unitid: obj.value,
                    control_type: 0,
                    control_value: flag ? "0" : "1"
                }, function (rs) {
                    layer.close(loading);
                    // console.log(rs);
                })
            }, function (idx) {
                layer.close(idx);
                var em = $(obj.othis[0]);
                if (!flag) {
                    obj.othis[0].classList.add('layui-form-onswitch');
                    em.children('em').text('是');
                    obj.elem.checked = true;
                } else {
                    obj.othis[0].classList.remove('layui-form-onswitch');
                    em.children('em').text('否');
                    obj.elem.checked = false;
                }
            });

        });

        form.on('switch(nelist-enable)', function (obj) {
            var flag = obj.elem.checked;
            var text = "确定要列入负面清单吗？";
            if (!flag) {
                text = "确定要拉出负面清单吗？";
            }
            layer.confirm(text, {
                icon: 3,
                title: '提示'
            }, function (index) {
                layer.close(index);
                let loading = layer.load();
                $.post(DATA_PATH + "control", {
                    unitid: obj.value,
                    control_type: 1,
                    control_value: flag ? "0" : "1"
                }, function (rs) {
                    layer.close(loading);
                    // console.log(rs);
                })
            }, function (idx) {
                layer.close(idx);
                var em = $(obj.othis[0]);
                if (!flag) {
                    obj.othis[0].classList.add('layui-form-onswitch');
                    em.children('em').text('是');
                    obj.elem.checked = true;
                } else {
                    obj.othis[0].classList.remove('layui-form-onswitch');
                    em.children('em').text('否');
                    obj.elem.checked = false;
                }
            });
        });
        window.saveOrUpdate = function (obj) {
            layer.open({
                type: 2,
                // title: '新增',
                title: obj ? '修改外包单位' : '新增外包单位',
                shade: 0.1,
                // area: [common.isModile() ? '100%' : '500px', common.isModile() ? '100%' : '400px'],
                area: [common.isModile() ? '100%' : '800px', common.isModile() ? '100%' : '400px'],
                content: VIEW_PATH + 'saveOrUpdate' + (obj ? "?id=" + obj.data.id : "")
            });
        }

        window.remove = function (obj) {
            layer.confirm('确定要删除该用户', {
                icon: 3,
                title: '提示'
            }, function (index) {
                layer.close(index);
                let loading = layer.load();
                $.ajax({
                    url: DATA_PATH + "remove?ids=" + obj.data['id'],
                    dataType: 'json',
                    type: 'post',
                    success: function (result) {
                        layer.close(loading);
                        if (result.code == 0) {
                            layer.msg("操作成功", {
                                icon: 1,
                                time: 1000
                            }, function () {
                                obj.del();
                            });
                        } else {
                            layer.msg("操作失败", {
                                icon: 2,
                                time: 1000
                            });
                        }
                    }
                })
            });
        }

        window.batchRemove = function (obj) {
            var checkIds = common.checkField(obj, 'id');
            if (checkIds === "") {
                layer.msg("未选中数据", {
                    icon: 0,
                    time: 1000
                });
                return false;
            }
            layer.confirm('确定要删除这些用户', {
                icon: 3,
                title: '提示'
            }, function (index) {
                layer.close(index);
                let loading = layer.load();
                $.ajax({
                    url: DATA_PATH + "remove?ids=" + checkIds,
                    dataType: 'json',
                    type: 'post',
                    success: function (result) {
                        layer.close(loading);
                        if (result.code == 0) {
                            layer.msg("操作成功", {
                                icon: 1,
                                time: 1000
                            }, function () {
                                table.reload('busUnit-table');
                            });
                        } else {
                            layer.msg("操作失败", {
                                icon: 2,
                                time: 1000
                            });
                        }
                    }
                })
            });
        }

        window.refresh = function (param) {
            table.reload('busUnit-table');
        }
    })
</script>
</body>
</html>
